<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>权限管理</title>
	<link href="__PUBLIC__/layui/css/layui.css" rel="stylesheet" />
	<link rel="stylesheet" href="__PUBLIC__/css/global.css" media="all">
	<link href="__PUBLIC__/Font-Awesome/css/font-awesome.css" rel="stylesheet" />
</head>

<body>
<div class="admin-main">
	<blockquote class="layui-elem-quote">权限分配

	</blockquote>
	<fieldset class="layui-elem-field">
		<legend>权限分配</legend>
		<div class="layui-field-box">
			<form class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">权限列表</label>
					<foreach name="menus" item="vo" key="k">
						<div class="layui-input-block">
							<input type="checkbox" name="menu[{$vo.act_id}]" value="{$vo['act_id']}" title="{$vo.act_name}" class="level_one" <?php if(in_array($vo['act_id'],$rulesArr)){echo "checked";} ?>>
							<foreach name="vo[$vo['act_id']]" item="v">
								<div class="layui-input-block">
									<input type="checkbox" name="menu[{$v.act_id}]" title="{$v.act_name}" value="{$v['act_id']}" class="level_two" <?php if(in_array($v['act_id'],$rulesArr)){echo "checked";} ?>>
									<foreach name="v[$v['act_id']]" item="v1">
										<div class="layui-input-block">
											<input type="checkbox" name="menu[{$v1.act_id}]" title="{$v1.act_name}" value="{$v1['act_id']}" class="level_three" <?php if(in_array($v1['act_id'],$rulesArr)){echo "checked";} ?>>
											<div class="layui-input-block">
												<?php foreach($v1[$v1['act_id']] as $v2){?>
												<input type="checkbox" name="menu[<?php echo $v2['act_id'];?>]" title="<?php echo $v2['act_name'];?>" value="<?php echo $v2['act_id'];?>" class="level_four" <?php if(in_array($v2['act_id'],$rulesArr)){echo "checked";} ?>>
												<?php }?>
											</div>
										</div>
									</foreach>
								</div>
							</foreach>
						</div>
					</foreach>
				</div>
				<?php if($type != 0){?>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<a class="layui-btn" lay-submit lay-filter="auth">立即提交</a>
						<a class="layui-btn layui-btn-primary" onclick="window.history.back()" >返回</a>
					</div>
				</div>
				<?php }else{ ?>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<a class="layui-btn layui-btn-primary" onclick="window.history.back()" >返回</a>
					</div>
				</div>
				<?php }?>
				<input type="hidden" name="role_id" value="{$role_id}">
			</form>
		</div>
	</fieldset>
</div>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script>
    layui.use(['layer','form'], function() {
        var form = layui.form(),
            $ = layui.jquery;

        $('.layui-form-checkbox').on('click', function (e){
            var children = $(this).parent('.layui-input-block').find('.layui-form-checkbox');
            var input = $(this).parent('.layui-input-block').find('input');

            if($(this).prev('input').hasClass('level_four')){
                if($(this).hasClass('layui-form-checked') == true){
                    $(this).addClass('layui-form-checked')
                    $(this).prev('input').prop('checked',true);
                }else{
                    $(this).removeClass('layui-form-checked');
                    $(this).prev('input').prop('checked',false);
                }
            }else{
                if($(this).hasClass('layui-form-checked') == true){
                    children.addClass('layui-form-checked')
                    input.prop('checked',true);
                }else{
                    children.removeClass('layui-form-checked');
                    input.prop('checked',false);
                }

            }

        });

        form.on('submit(auth)', function(data){

            var menu_ids = data.field;
            var url = "__SELF__";
            $.post(url,menu_ids,function(data){
                if(data.code == '101'){
                    layer.msg(data.msg, {
                        icon: 6,
                        time: 2000
                    }, function(){
                        history.back();
                    });

                }else{
                    layer.msg(data.msg,{icon: 5});
                    return;
                }
            })
            return false;
        });

    });
</script>
</body>

</html>